import { BusinessStatus } from './../../../enum';
import { request } from '../../request';

export function fetchUserPage(page: Common.Page<SysAuth.UserInfo>, searchData: any) {
  return request({
    url: '/sys/user/list',
    data: { page, searchData },
    method: 'POST',
  });
}

export function fetchUser(id: Common.IdType) {
  return request({
    url: `/sys/user/${id}`,
    method: 'GET',
  });
}

export function fetchAddUser(data: SysAuth.UserInfo) {
  return request({
    url: '/sys/user',
    data: data,
    method: 'POST',
  });
}

export function fetchUpdateUser(data: SysAuth.UserInfo) {
  return request({
    url: '/sys/user',
    data: data,
    method: 'PUT',
  });
}

export function fetchUserResetPw(id: Common.IdType) {
  return request({
    url: `/sys/user/resetPw/${id}`,
    method: 'PUT',
  });
}

export function fetchDeleteUser(ids: Common.IdType[]) {
  return request({
    url: `/sys/user/${ids}`,
    method: 'DELETE',
  });
}

export function fetchUpdateUserStatus(id: Common.IdType, status: BusinessStatus) {
  return request({
    url: `/sys/user/status/${id}/${status}`,
    method: 'PUT',
  });
}

export function fetchUnbanUser(id: Common.IdType) {
  return request({
    url: `/sys/user/unban/${id}`,
    method: 'PUT',
  });
}

export function fetchExportUser(searchData: any) {
  return request({
    url: '/sys/user/export',
    data: searchData,
    method: 'POST',
    responseType: 'blob',
  });
}

export function fetchExportTemplateUser() {
  return request({
    url: '/sys/user/export/template',
    method: 'GET',
    responseType: 'blob',
  });
}

export function fetchImportUser(file: FormData) {
  return request({
    url: '/sys/user/import',
    data: file,
    method: 'POST',
  });
}
